package ru.tulupov.exerunner;

import java.io.IOException;
import java.util.Scanner;

/**
 * Executing another program
 * 
 * @author <a href="mailto:zhekka3@gmail.com">Eugene Tulupov</a>
 */
public class Main {
	public static void main(String[] args) {
		try {
			System.out.println("Exe runner");
			System.out.println("Please enter a command");

			Scanner scanner = new Scanner(System.in);
			String command = scanner.nextLine();

			Runtime runtime = Runtime.getRuntime();
			Process process = runtime.exec(command);

			StreamAdapter stdin = new StreamAdapter(System.in,
					process.getOutputStream());
			StreamAdapter stdout = new StreamAdapter(process.getInputStream(),
					System.out);
			StreamAdapter stderr = new StreamAdapter(process.getErrorStream(),
					System.err);

			stdin.start();
			stdout.start();
			stderr.start();

			process.waitFor();
			System.exit(0);
		} catch (IOException e) {
			System.err.println("File not found!");
		} catch (InterruptedException e) {

		}
	}
}
